/**********************  Write Trigger Processing ****************************************/

/*****************************************************************************************
	{1}		old buffer
	{2}		new buffer
	{3}		table name 
	{4}		field name
	{5}		type
	{6}		key	
	{7}		key1
	{8}		key2
	{9}		key3
	{10}	key4
	{11}	key5
	{12}	key6
	{13}	key7
	{14}	key8
	
example :

	HK:
	do:
        if not can-find ( first dt_mstr where dt_table = "pt_mstr" and dt_type = "MOD" ) then leave HK.
        
        if not can-find ( first wf_old_pt_mstr ) then do:
            create wf_old_pt_mstr.
            if recid(wf_old_pt_mstr)= -1 then .
        end.
        
        buffer-copy old_pt_mstr to wf_old_pt_mstr no-error.

        for each dt_mstr no-lock where dt_table = "pt_mstr" and dt_type = "MOD" :
        
        	run value(global_user_lang_dir + "hk\hkmodtrig.p")
       			"wf_old_pt_mstr"		/*old buffer*/
       			"pt_mstr"				/*new buffer*/
       			dt_table				/*table name*/
       			dt_field				/*field name*/
       			dt_type					/*type*/
       			recid(pt_mstr)			/*key*/	
       			pt_mstr.pt_part			/*key1*/
       			""						/*key2*/
       			""						/*key3*/
       			""						/*key4*/
       			""						/*key5*/
       			""						/*key6*/
       			""						/*key7*/
       			""						/*key8*/
       			.
			
        end.
	end.
*****************************************************************************************/

{mfdeclre.i}

define shared work-table {1} like {3}.

for first {2} where recid({2}) = {6} no-lock:
end.

for first {1} no-lock:
end.

if available {1} and available {2} and {1}.{4} <> {2}.{4} then do:

    FOR FIRST _myconnection NO-LOCK,
        FIRST _Connect NO-LOCK WHERE _myconn-userid = _connect-usr:
/*                                                   */
/*     /*   DISPLAY _connect-device _connect-usr. */ */
/*     /*   DISPLAY mon_mstr.                     */ */
/*       DISPLAY _connect WITH 2 COLUMNS.            */



	create dth_hist .

	assign
		dth_type = "{5}"
		dth_mod_date = today
		dth_mod_time = time
		dth_userid = global_userid 
		dth_table = "{3}"
		dth_field = "{4}"
		dth_bef_val = string({1}.{4})
		dth_aft_val = string({2}.{4})
		dth_program = execname
    dth_net_user = _connect-Name
    dth_net_dev  = _connect-device
		dth_key = {6}
		dth_key1 = "{7}"
		dth_key2 = "{8}"
		dth_key3 = "{9}"
		dth_key4 = "{10}"
		dth_key5 = "{11}"
		dth_key6 = "{12}"
		dth_key7 = "{13}"
		dth_key8 = "{14}"
		.
    
    END.  	
	qad_next_seq:
	do while true on error undo, retry:
		do on error undo, leave:
			assign dth_trnbr = next-value(dth_sq01).
			if dth_trnbr = 0 then next qad_next_seq.
			leave qad_next_seq.
		end.
	end.
		
end.
